package com.example.smartcity_40.lawyer;

import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.ImageView;

import com.example.smartcity_40.R;
import com.example.smartcity_40.lawyer.apter.AddLaeyerSeekApter;
import com.example.smartcity_40.lawyer.apter.PreferredlawyerApter;
import com.example.smartcity_40.lawyer.bean.AddLaeyerSeekBean;
import com.example.smartcity_40.lawyer.bean.PreferredlawyerBean;
import com.example.smartcity_40.tool.Tool;

import kotlin.Unit;
import kotlin.jvm.functions.Function1;

public class AddLaeyerSeekActivity extends AppCompatActivity {

    private AddLaeyerSeekActivity context;
    private Tool tool;
    private RecyclerView lawyerlist;
    private AddLaeyerSeekApter addLaeyerSeekApter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_add_laeyer_seek);
        context = this;
        initview();
        preferredlawyer();
    }

    private void preferredlawyer() {
        tool.send("/prod-api/api/lawyer-consultation/lawyer/list",
                Tool.GET,
                null,
                true,
                AddLaeyerSeekBean.class,
                new Function1<AddLaeyerSeekBean, Unit>() {
                    @Override
                    public Unit invoke(AddLaeyerSeekBean addLaeyerSeekBean) {
                        if (addLaeyerSeekBean.getCode() == 200) {
                            lawyerlist.setLayoutManager(new LinearLayoutManager(context));
                            addLaeyerSeekApter.setDate(addLaeyerSeekBean.getRows());
                            lawyerlist.setAdapter(addLaeyerSeekApter);
                        }
                        return null;
                    }
                });
    }

    private void initview() {
        ImageView back = findViewById(R.id.back);
        lawyerlist = findViewById(R.id.lawyerlist);
        tool = new Tool(context);
        addLaeyerSeekApter = new AddLaeyerSeekApter(context);
        Log.e("TAG",tool.get("token"));
        back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                context.finish();
            }
        });
    }
}